package tech.cn.note.word.test;

import java.math.BigDecimal;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.io.FileUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import tech.cn.note.excel.test.dto.CustomPositionReportDTO;
import tech.cn.note.word.PoiTemplateDataFillServiceImpl;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/word")
@Slf4j
@Validated
public class WordTestController {

    private final PoiTemplateDataFillServiceImpl poiTemplateDataFillService;

    @GetMapping("/test")
    public void generatorWord() throws Exception {
        byte[] bytes = FileUtil.readBytes(Paths.get("./script/file/word/word.docx"));
        Map<String, Object> valueMap = new HashMap<>();
        valueMap.put("name", "黑悟空");
        UserDTO user = new UserDTO();
        user.setAddr("花果山");
        user.setDesc("齐天大圣1");
        user.setAge(new BigDecimal(18));
        user.setDate(LocalDate.now());
        user.setSex("man");
        user.setPercent(new BigDecimal("0.1"));
        valueMap.put("user", user);
        List<CustomPositionReportDTO> list = new ArrayList<>();
        CustomPositionReportDTO dto1 = new CustomPositionReportDTO();
        dto1.setTradeId("2024-013_000001");
        dto1.setEffectiveNotional(new BigDecimal("1000000"));

        CustomPositionReportDTO dto2 = new CustomPositionReportDTO();
        dto2.setTradeId("2024-013_000002");
        dto2.setEffectiveNotional(new BigDecimal("88888"));
        list.add(dto1);
        list.add(dto2);
        valueMap.put("list", list);

        byte[] bytes1 = poiTemplateDataFillService.writeToByte(valueMap, bytes);

        FileUtil.writeBytes(bytes1, System.getProperty("user.dir")+"/word.docx"); ;

    }
}
